﻿using System;
using System.Runtime.CompilerServices;
using Elasticsearch.Synchronize.Repository.Interface;
using Elasticsearch.Synchronize.Repository.MongoDbDTO;
using Elasticsearch.Synchronize.Repository.Settings;
using Microsoft.Extensions.Options;
using MongoDB.Driver;

namespace Elasticsearch.Synchronize.Repository.DBContext
{
    public class MongoDbContext : IMongoDbContext
    {
        private readonly IMongoClient _client;

        public MongoDbContext(MongoDbSettings settings)
        {
            _client = new MongoClient(settings.ConnectionUrl);
            Console.WriteLine("连接字符串");
            Console.WriteLine(settings.ConnectionUrl);
        }

        public IMongoDatabase SyncConfigDatabase =>
            _client.GetDatabase("HeXinDB");

        public IMongoCollection<SynchronizeRuleDTO> SynchronizeRule =>
           SyncConfigDatabase.GetCollection<SynchronizeRuleDTO>("SynchronizeRule");


        public IMongoCollection<SynchronizeItemDTO> SynchronizeItem =>
            SyncConfigDatabase.GetCollection<SynchronizeItemDTO>("SynchronizeItem");
    }
}